import { ProTable } from "@ant-design/pro-components"
import { PageContainer } from "@ant-design/pro-layout"
import { useAxiosGet, useCtx, useParams } from "@sker/sdk"
import { renderAdminPage } from "@sker/ui"
import { Button, Popconfirm, Tabs } from "antd"

export const FilesPage: React.FC<{}> = ({ }) => {
    const { params, onChange } = useParams<any>({ type: '1' })
    const { fetch: fetchTaskList } = useAxiosGet('autojs/core/web/script/scriptList')
    const { history } = useCtx()
    const getColumns = () => {
        if (params.type === `1`) {
            return [
                { dataIndex: 'title', title: '任务名' },
                { dataIndex: 'name', title: '英文名' },
            ]
        } else {
            return [
                { dataIndex: 'package_name', title: '包名' },
                { dataIndex: 'activity_name', title: '页面' },
                { dataIndex: 'desc', title: 'j简介' },
            ]
        }
    }
    return <PageContainer title={'脚本管理'}>
        <Tabs activeKey={params.type} onChange={e => {
            onChange({ type: e })
        }} items={[
            { label: '已拦截', key: '1' },
            { label: '未处理', key: '2' },
        ]}></Tabs>
        <div className="h-24px"></div>
        <ProTable rowKey={'id'} search={false} toolBarRender={false} params={params} columns={[
            { dataIndex: 'id', title: '编号' },
            ...getColumns(),
            {
                title: '操作', render(dom, entity, index, action, schema) {
                    return <>
                        <Button size={'small'} type={'link'} onClick={e => {
                            history.push(`/autojs/core/web/scriptEdit?type=${params.type}&id=${entity.id}`)
                        }}>编辑</Button>
                        <Popconfirm onConfirm={async e => {
                        }} title={'此操作不可逆!您确定要执行此操作吗？'} description={'删除后无法恢复，请慎重操作！！'}>
                            <Button size={'small'} type={'link'} danger >删除</Button>
                        </Popconfirm>
                    </>
                },
            }
        ]} request={(params, sort, filter) => fetchTaskList(params)}></ProTable>
    </PageContainer>
}
renderAdminPage(FilesPage, 'autojs/core/web/script')
